<?php
//-----
//fifth

$buffer="";
//h�r s� blir det fel dag vald!!!
if (!$nonews) {
    if ($latest['mainlink_activated'])
    {
        $mainlink = $latest['mainlink'];
        $needProtocol = true;
        if (substr($mainlink,0,7)=="http://" ) $needProtocol = false;
        elseif( substr($mainlink,0,8)=="https://") $needProtocol = false;

        if ($needProtocol) $mainlink = "http://$mainlink";
        if (strpos($mainlink,"klimatsmart.se") === false) $mainlink .= '" target="_blank';
    }
    $title = $latest['title'];
    $text = $latest['text'];
    $text2 = $latest['text2'];

    if (isset($mainlink)) {
        $title = "<a href=\"$mainlink\">$title</a>";
    }
    $dates[] = $latest['date_publish'];
    $dates[] = $latest['date_publish2'];
    $dates[] = $latest['date_publish3'];
    $dates[] = $latest['date_publish4'];
    rsort($dates);
    foreach ($dates as $k => $v)
    {
        if ($v >= date("Y-m-d H:i:s")) unset($dates[$k]);
    }
    reset($dates);
    $date = each($dates);
    $date = $date[1];

    echo "<span style=\"float:right\"><small>".substr($date,0,10)."</small></span><br/>";
    if ($latest['img_file'])
    {
        echo "<div style=\"float:right;padding:2px;text-align:center;\">";
        if (isset($mainlink)) echo "<a href=\"$mainlink\">";
        echo "<img src=\"http://".$server[minIndexAndIncreas($serverUsed)]."/images/news/$latest[img_file]\" style=\"margin-bottom:2px\"/>";

        echo "<br/><small>$latest[img_description]</small>";
        if (isset($mainlink)) echo "</a>";
        echo "</div>";
    }

    echo "<div class=\"style18\"><strong><span style=\"color:green\">$title</span></strong></div><br/>";
    if (isset($mainlink)) echo "<a href=\"$mainlink\">", nl2br($text), "</a>";
    else echo nl2br(hyperlink($text));
    if ($text2) echo "<br/>", nl2br(hyperlink($text2));
    echo "<br/><br/>";
    if ($latest['text_source'])
    {
        $sources = unserialize($latest['text_source']);
        $sources_activated = unserialize($latest['text_source_activated']);
        if (is_array($sources))
        {

            foreach ($sources as $k=>$v)
            {
                if ($v[0] && $sources_activated[$k])
                {
                    $v[0] = trim($v[0]);
                    $v[1] = trim($v[1]);
                    //if (substr($v[1],0,7) != "http://") $v[1] = "http://$v[1]";

                    $needProtocol = true;
                    if (substr($v[1],0,7)=="http://" ) $needProtocol = false;
                    elseif( substr($v[1],0,8)=="https://") $needProtocol = false;
                    if ($needProtocol) $v[1] = "http://$v[1]";

                    $b = "<a href=\"$v[1]\"";
                    if (strpos($v[1],"klimatsmart.se") === false) $b .= ' target="_blank"';
                    $b .= ">$v[0]</a>";
                    $v = $b;
                    $buffer[] = $v;
                }
            }
            echo "<small>";
            if ($buffer) echo "K&auml;ll".(count($buffer)>1? "or":"a").": ".implode(", ", $buffer);
        }
    }
    /*else
    {
            echo "<small>";
            if(isset($mainlink))
                    echo 'K�lla: <a href="'.$mainlink.'">'.$latest['text_source'].'</a>';
            else
                    echo 'K�lla: Ok�nd';
    }*/
    if ($latest['img_source'] && $latest['img_file'])
    {
        echo '<!-- '.($latest['img_url_activated']+0).' -->';
        if($latest['img_url_activated']==1)
        {
            echo "<br/>Foto: <a href=\"$latest[img_url]\" target=\"_blank\">$latest[img_source]</a>";
        }
        else
        {
            echo "<br/>Foto: $latest[img_source]";
        }
    }
    echo "</small>";
}
else echo "Ingen nyhet att visa.";

//fifth
//------
?>